<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 从双倍数组中还原原数组 -->
    <script>
      var findOriginalArray = function (changed) {
        if (changed.length & 1) return []
        changed.sort((a, b) => a - b)
        let map = {}
        let ans = []
        for (let num of changed) map[num] = (map[num] || 0) + 1
        for (let num of changed) {
          if (!map[num]) continue
          if (!map[num * 2]) return []
          map[num]--, map[num * 2]--
          ans.push(num)
        }
        return ans
      }
      console.log(findOriginalArray([1, 3, 4, 2, 6, 8]))
    </script>
  </body>
</html>
